﻿using System;
using System.Collections.Generic;
using TallyBook.DAL.Repository;
using TallyBook.DAL.Repository.Imp;

namespace TallyBook.BLL.Service.Imp
{
    public class AccountService : IAccountService<Account>
    {
        private readonly IRepository<Account> _repository = RepositoryFactory<Account>.Instance.CreatRepository();

        public int Update(long accounttypeid, long accountid, string accountname, decimal initmoney,
            decimal currentmoney, string comment, DateTime time)
        {
            var accounts = new Account
            {
                Id = accountid,
                Name = accountname,
                InitMoney = initmoney,
                CurrentMoney = currentmoney,
                Comment = comment,
                AccountTypeId = accounttypeid,
                CreateTime = time
            };
            return _repository.Update(accounts);
        }

        public int Insert(long accounid, long accounttypeid, string accountname, decimal initmoney, decimal currentmoney,
            string comment, DateTime time)

        {
            var accounts = new Account
            {
                Id = accounid,
                Name = accountname,
                InitMoney = initmoney,
                CurrentMoney = currentmoney,
                Comment = comment,
                CreateTime = time,
                AccountTypeId = accounttypeid
            };
            return _repository.Insert(accounts);
        }

        public int Delete(long id)
        {
            var account = new Account
            {
                Id = id
            };
            return _repository.Delete(account);
        }

        public Account Get(long id)
        {
            return _repository.Get(id);
        }

        public List<Account> GetAll()
        {
            return _repository.GetAll();
        }

        public List<AccountType> GetName()
        {
            AccountRepository accountTypeRepository = RepositoryFactory<AccountType>.Instance.AccountTypeRepository();
            return accountTypeRepository.GetName();
        }
    }
}